#!/bin/sh

ipv6_disable_nat() {
  NAT6=`uci -q get firewall.nat6.reload`
  if [ "$NAT6" = "1" ]; then
    uci -q delete network.wan6.sourcefilter
    uci -q delete firewall.nat6
    uci commit firewall
    /etc/init.d/firewall restart
  fi
}

ipv6_dns_on() {
	uci -q delete 'dhcp.@dnsmasq[0].filter_aaaa'
}

ipv6_half_mode() {
	uci -q batch <<-EOF >/dev/null
		del network.wan.ipv6
		del network.wan6.auto

		del dhcp.wan6

		set dhcp.lan.ra='relay'
		del dhcp.lan.ra_slaac
		del dhcp.lan.ra_flags
		set dhcp.lan.dhcpv6='relay'
		set dhcp.lan.ndp='relay'
EOF
	ipv6_dns_on
}

# disable ipv6 nat
ipv6_disable_nat

ipv6_half_mode

uci -q batch <<-EOF >/dev/null
	commit dhcp
	commit network
EOF

/etc/init.d/odhcpd reload
/etc/init.d/dnsmasq reload
/etc/init.d/network reload

echo "Done"
